
package com.ami.kvm.jviewer.kvmpkts;

import com.ami.kvm.jviewer.Debug;
import java.net.Socket;
import java.nio.ByteBuffer;

public class FragReader implements KVMReader {
	private KVMClient m_client;
	private byte[] m_frameBuf;
	private ByteBuffer m_frameByteBuf;
	private int m_fragIx;
	private int m_frameIx;

	public FragReader(KVMClient paramKVMClient) {
		this.m_client = paramKVMClient;

		this.m_frameBuf = new byte[9216000];
		this.m_frameIx = 0;
		this.m_frameByteBuf = ByteBuffer.wrap(this.m_frameBuf);
	}

	public void initialize() {
		if ((this.m_client.m_fragNum & 0x7FFF) == 0) {
			this.m_frameIx = 0;
		}

		this.m_frameByteBuf.position(this.m_frameIx);
		this.m_frameByteBuf.limit(this.m_frameIx + this.m_client.m_pktHdr.pktSize - 2);
		this.m_fragIx = 0;
	}

	public int read(Socket paramSocket) {
		try {
			byte[] arrayOfByte = new byte[this.m_frameByteBuf.remaining()];
			this.m_fragIx = this.m_client.read_data(paramSocket, arrayOfByte);
			this.m_frameByteBuf.put(arrayOfByte);
		} catch (Exception localException) {
			Debug.out.println("FRAG_RDR ");
			Debug.out.println(localException);
			return -1;
		}

		if (this.m_fragIx == this.m_client.m_pktHdr.pktSize - 2) {
			this.m_frameIx += this.m_fragIx;

			if (0 != (this.m_client.m_fragNum & 0x8000)) {
				this.m_frameByteBuf.limit(this.m_frameIx);

				this.m_client.onNewFrame(this.m_frameByteBuf);
				this.m_frameIx = 0;
			}

			HeaderReader localHeaderReader = this.m_client.getHdrReader();
			localHeaderReader.initialize();
			this.m_client.setState(localHeaderReader);
		}
		return 0;
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\kvmpkts\
 * FragReader.class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */